<template>
	<view class="">
		<!-- <u-navbar :is-back="false" title="全部课程"></u-navbar> -->
		<view>
			<cp-goods-select height="90vh" :props="{label:'label',value:'value',children:'children'}" :options="list" @category-change="handelCategoryChange">
					<cp-goods-select-goods customClass="cloumn-2" @scrolltolower="handelScrolltolower" @getAll="getAllHandler">
						<template v-slot:default="{scope}">
						   <view class="cp-goods-select-goods__item" @click="itemClick(scope)">
							 {{ scope.label}} 
						   </view>
						 </template>
					</cp-goods-select-goods>
			</cp-goods-select>
			
		</view>
	</view>
</template>

<script>
	import cpGoodsSelect from '@/uni_modules/cp-goods-select/components/cp-goods-select/cp-goods-select'
	export default {
		components:{cpGoodsSelect},
		data() {
			return {
				list:[],
				goods:[]
			}
		},
		onLoad() {
			//this.list = this.initList()
			
			this.initData();
		},
		methods: {
			initData(){
				this.$http.getClassifyInfoList().then(res=>{
					console.log(res)
					
					let arr  = res.data.reduce((ls,item)=>{
						let obj= Object.assign({});
						obj.label =item.name
						obj.value= item.specialId
						obj.children = []
						obj.children=item.children.map(item2=>{
							item2.label =item2.name
							item2.value= item2.specialId
							return item2
						})
						ls.push(obj)
						return ls
					},[]);
					console.log(arr,1)
					
					this.list = arr
				})
			},
			getAllHandler(data){
				console.log(data)
				this.goCurriculum(data.value,0);
			},
			itemClick(data){
				this.goCurriculum(data.pid,data.specialId)
			},
			goCurriculum(type1,type2){
				
				const eventChannel = this.getOpenerEventChannel()
				eventChannel.emit('getNextPageData', {type1:type1,type2:type2});
				uni.navigateBack({
					delta:1
				})
			},
			initList(){
				let result = []
				let i = 0 
				while(++i < 20){
					let children =[ ]
					let j = 0
					while(++j < 10){
						children.push({label:'商品'+j, value:j,})
					}
					result.push({
						label:'分类'+i,
						value:i,
						children:children
					})
				}
				return result
			},
			handelScrolltolower(e){
				console.log('handelScrolltolower',e)
			},
			handelCategoryChange(e){
				console.log('handelCategoryChange',e)
				let goods =[],j=0;
				while(++j < 10){
					goods.push({label:e.label+': 商品'+j, value:j,})
				}
				this.goods = goods
			}
		}
	}
</script>

<style>
</style>
